﻿<div ng-controller="Customer_DetailC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">客户详情</h1>
    </div>
    <div class="modal fade" id="tupian" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <!--<h4 class="modal-title" id="myModalLabe3">收货凭证 </h4>-->
                <!--<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>-->
                <img style="width: 100%;" ng-src="/file/customer/{{editReceiptdata}}" alt="客户凭证">
            </div>
        </div>
    </div>
    <div class="modal fade" id="shangchuan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form id="myupload" action={{myurl}} method="post" enctype="multipart/form-data">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabe2">上传客户凭证 </h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group btn">
                            <!--<input type="label" name="label" id="label" class="form-control" placeholder="请选择文件" /><br />-->
                            <label style="margin-right: 10px;">请选择文件</label>
                            <input type="file" name="file1" id="fileupload" class="form-control" value="" /><br />
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span>
                        </div>
                        <!-- 显示已上传的文件名 -->
                        <div class="files"></div>
                        <!-- 显示已上传的图片-->
                        <div class="showimg"></div>
                    </div>
                    <div class="modal-footer">
                        <!--<button type="button" class="btn btn-success" ng-disabled="myform1.$invalid" ng-click="okchange()">确认提交</button>-->
                        <input type="button" class="btn btn-default" ng-click="gosubmit2()" value="提交" />
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="h4">客户详情</span>
                        </div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label>简称 <em class="text-muted">(2-15字符)</em></label>
                                <input type="text" class="form-control" ng-model="data.ShortName" disabled minlength="2" maxlength="15">
                            </div>
                            <div class="form-group">
                                <label>名称</label>
                                <input type="text" disabled class="form-control" ng-model="data.Name">
                            </div>
                            <div class="form-group">
                                <label style="margin-right: 10px;">是否个人账户</label>
                                <label class="i-switch bg-info">
                                    <input type="checkbox" disabled ng-model="data.IsPersonal">
                                    <i></i>
                                </label>
                            </div>

                            <div class="form-group">
                                <label>地区 </label>
                                <div class="input-group ">
                                    <span class="input-group-addon">省</span>
                                    <input type="text" disabled class="form-control" ng-model="data.District.Parent.Name">
                                    <span class="input-group-addon">市</span>
                                    <input type="text" disabled class="form-control" ng-model="data.District.Name">
                                </div>
                            </div>

                            <div class="form-group">
                                <label>地址</label>
                                <input type="text" disabled class="form-control" ng-model="data.Address">
                            </div>
                            <!--<div class="form-group">
                                <label>联系人</label>
                                <input type="text" disabled class="form-control" ng-model="data.Contacts">
                            </div>
                            <div class="form-group">
                                <label>电话</label>
                                <input type="text" disabled class="form-control" ng-model="data.ContactPhone" required ng-pattern="/^[1][3-8]\d{9}$/" value="{{datauser.Phone}}">
                            </div>


                            <div class="form-group">
                                <label>财务</label>
                                <input type="text" disabled class="form-control" ng-model="data.Accountant">
                            </div>
                            <div class="form-group">
                                <label>财务电话</label>
                                <input type="text" disabled class="form-control" ng-model="data.AccountantPhone" required ng-pattern="/^[1][3-8]\d{9}$/" value="{{datauser.Phone}}">
                            </div>-->
                            <!--------------------动态加载联系人行 Start--------------------------------------------------->

                            <div class="form-group">
                                <div id="Contacts-wraper">
                                    <div class="Contacts-inner" ng-repeat="x in data.CustomerContacts">
                                        <label>联系人{{$index + 1}}</label>
                                        <input type="text" ng-model="x.ContactUser" disabled>
                                        <label>电话(必填)</label>
                                        <input type="text" ng-model="x.ContactPhone" required ng-pattern="/^[1][3-8]\d{9}$/" disabled>
                                    </div>
                                    <!--<button type="button" class="btn btn-default" ng-click=" AddContact()">新增</button>
                                    <button type="button" class="btn btn-default" ng-click="remove()">删除</button>-->
                                </div>
                            </div>



                            <div class="form-group">
                                <div id="Contacts-wraper">
                                    <div class="Contacts-inner" ng-repeat="x in data.AccountantContacts">
                                        <label>财务{{$index + 1}}</label>
                                        <input type="text" ng-model="x.ContactUser" disabled>
                                        <label>财务电话</label>
                                        <input type="text" ng-model="x.ContactPhone" ng-pattern="/^[1][3-8]\d{9}$/" disabled>
                                    </div>
                                    <!--<button type="button" class="btn btn-default" ng-click=" AddAccountantContact()">新增</button>
                                    <button type="button" class="btn btn-default" ng-click="removeAccountant()">删除</button>-->
                                </div>
                            </div>
                            <!--------------------End--------------------------------------------------->
                            <div class="form-group">
                                <label>客户专员</label>
                                <input type="text" disabled class="form-control" ng-model="data.ClientManager.Name">
                            </div>
                            <div class="form-group">
                                <label>户头</label>
                                <input type="text" disabled class="form-control" ng-model="data.Accounts.length" />
                            </div>

                            <div class="form-group">
                                <label>身份证号</label>
                                <input type="text" disabled class="form-control" ng-model="data.IDCode">
                            </div>
                            <div class="form-group">
                                <label>信用代码</label>
                                <input type="text" disabled class="form-control" ng-model="data.CreditID">
                            </div>
                            <div class="form-group">
                                <label>备注</label>
                                <input type="text" disabled class="form-control" ng-model="data.Remarks">
                            </div>
                            <div class="form-group">
                                <label>评分</label>
                                <input type="text" disabled class="form-control" ng-model="data.CreditScore">
                            </div>
                            <div class="form-group">
                                <label>状态:</label>
                                <label ng-if="data.ApprovalState == 0">等待审批</label>
                                <label ng-if="data.ApprovalState == 1">审批中</label>
                                <label ng-if="data.ApprovalState == 2">通过</label>
                                <label ng-if="data.ApprovalState == 3">已驳回</label>
                            </div>
                            <!--<div class="form-group">-->
                            <!--<accordion close-others="oneAtATime">-->
                            <!--<accordion-group heading="查看客户交易数据➤">-->
                            <!--<ul>-->
                            <!--<li ng-repeat="item in orderdetaildata.Records | orderBy:['CreateTime']">-->
                            <!--{{item.CreateTime}}/<label ng-if="item.Price != 0">{{item.Price | number:2}}/</label>{{item.Remarks}}-->
                            <!--</li>-->
                            <!--</ul>-->
                            <!--</accordion-group>-->
                            <!--</accordion>-->
                            <!--</div>-->
                            <div class="form-group">
                                <accordion close-others="oneAtATime">
                                    <accordion-group heading="查看历史交易记录➤">
                                        <ul>
                                            <li ng-repeat="x in data.Accounts">
                                                账户：{{x.Name}}
                                                <br>
                                                余额：{{x.Amount}}
                                            </li>
                                            <li ng-repeat="x in Imgtitles1.Data">
                                                <accordion close-others="oneAtATime">
                                                    <accordion-group heading="{{x.SendTime}}➤">
                                                        供应商：{{x.Provider.Name}}
                                                        <br>
                                                        账户：{{x.Account.Name}}
                                                        <br>
                                                        金额/重量t：{{x.SourceTotal}}/{{x.SourceWeight}}t
                                                        <br>
                                                        <div class="form-group">
                                                            <label>订单状态：</label>
                                                            <span style="width:10%" ng-if="x.State == 0">待确认</span>
                                                            <span style="width:10%" ng-if="x.State == 1">驻厂确认</span>
                                                            <span style="width:10%" ng-if="x.State == 2">已发货</span>
                                                            <span style="width:10%" ng-if="x.State == 3">已收货</span>
                                                            <span style="width:10%" ng-if="x.State == 4">已结算</span>
                                                            <span style="width:10%" ng-if="x.State == 5">完结</span>
                                                            <span style="width:10%" ng-if="x.State == 6">取消</span>
                                                            <span style="width:10%" ng-if="x.State == 7">审核通过</span>
                                                            <span style="width:10%" ng-if="x.State == 8">已退货</span>
                                                            <span style="width:10%" ng-if="x.State == 9">已退款</span>
                                                            <span style="width:10%" ng-if="x.IsSettlement">已结算</span>
                                                        </div>
                                                    </accordion-group>
                                                </accordion>
                                            </li>
                                            <br>
                                        </ul>
                                    </accordion-group>
                                </accordion>
                            </div>
                            <div class="form-group">
                                <label>历史记录</label>
                                <div ng-bind-html="trustAsHtml(data.Record)"></div>
                            </div>
                            <div class="form-group" ng-if="Imgtitles.length >= 1">
                                <label>用户凭证：</label>
                                <img style="height: 50px; margin: 10px" ng-repeat="item in Imgtitles track by $index" ng-src="/file/customer/{{item.FileName}}" alt="用户凭证" ng-click="editReceipt(item)" data-toggle="modal" data-target="#tupian">
                            </div>
                        </div>
                        <footer class="panel-footer text-right bg-light lter">
                            <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#shangchuan">上传用户凭证</button>
                            <button class="btn btn-sm btn-default" ng-if="item.ApprovalState==0" ng-click="$state.go('app.Customer_Confirm', { 'id': item.Id,'from':0 })">审核</button>
                            <button type="button" class="btn btn-default" ng-if="data.ApprovalState==3" ng-click="$state.go('app.Customer_Edit', { 'id': data.Id,'action':'SelfList' })">修改</button>
                            <button type="button" class="btn btn-default" ng-click="$state.go('app.Customer_MyAccountList', { 'id': data.Id,'from':1 })">户头管理</button>
                            <button type="button" class="btn btn-default" ng-click="abolish()">取消</button>
                        </footer>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')
    .controller("Customer_DetailC", function ($scope, $state, $http, $stateParams) {
        $scope.myurl = "../api/Upload?customerId=" + $stateParams.id;
        $http.get("../api/Customer/Detail", { params: { "id": $stateParams.id } })
           .then(function (res) {
               $scope.data = res.data; console.log($scope.data);
               console.log($scope.data);
               $http.get("/api/Upload/GetCustomerInfo", { params: { "customerId": $stateParams.id } })
                       .then(function (res) {
                           console.log(res.data);
                           $scope.Imgtitles = res.data.Data;
                           console.log($scope.Imgtitles)
                       })
                       .then(function (error) {
                           if (error) {
                               alert("凭证获取失败");
                           }
                       });
           })
           .then(function (error) {
               if (error) {
                   alert("数据获取失败");
               }
           });
        $http.get("../api/Order/List?page=1&rows=9999&state=&keyword=&customerId=" + $stateParams.id)
                    .then(function (res) {
                        console.log(res.data);
                        $scope.Imgtitles1 = res.data;
                        console.log($scope.Imgtitles1)
                    })
                     .then(function (error) {
                         if (error) {
                             alert("凭证获取失败");
                         }
                     });
        //获取地市
        //$http({
        //    url: "/api/District",
        //    method: "GET"
        //})
        //    .then(function (res) {
        //        $scope.districts = res.data;
        //        for (var i = 0; i < $scope.districts.length; i++) {
        //            if ($scope.districts[i].Id == $scope.data.District.Parent.Id) {
        //                $scope.selectedDistrict1 = $scope.districts[i];
        //            }
        //        }
        //    })
        //    .then(function (error) {
        //        if (error) {
        //            console.log("error");
        //        }
        //    });
        $scope.edit = function () {
            console.log($scope.data);
            $http.put("/api/Customer", $scope.data)
           .then(function (res) {
               alert("保存成功");
           }).then(function (error) {
               alert("处理失败");

           })
            ;
        };
        //返回上一页
        $scope.abolish = function () {
            $state.go('app.Customer_SelfList');
        };
        //查看大图
        $scope.editReceipt = function (item) {
            $scope.editReceiptdata = item.FileName;
        };
        $scope.bar = $(".bar");//进度条
        $scope.percent = $('.percent');//获取上传百分比
        $scope.showimg = $('.showimg');//显示图片的div
        $scope.progress = $('.progress');//显示进度的div
        $scope.files = $('.files');//文件上传控件的input元素
        $scope.btn = $('.btn span'); //按钮文本
        $scope.gosubmit2 = function () {
            $("#myupload").ajaxSubmit({
                dataType: 'json',//返回数据类型
                beforeSend: function () {
                    $scope.showimg.empty();
                    $scope.progress.show();
                    $scope.percentVal = '0%';
                    $scope.bar.width($scope.percentVal);
                    $scope.percent.html($scope.percentVal);
                    $scope.btn.html('上传中..');
                },
                //更新进度条事件处理代码
                uploadProgress: function (event, position, total, percentComplete) {
                    $scope.percentVal = percentComplete + '%';
                    $scope.bar.width($scope.percentVal);
                    $scope.percent.html($scope.percentVal);
                },
                success: function (data) {//图片上传成功时
                    if (data) {
                        alert("上传成功");
                        $('#shangchuan').modal("hide");
                        $state.go('app.Customer_Detail', {
                            id: $stateParams.id
                        });
                    }
                },
                error: function (xhr) {
                    $scope.btn.html('上传失败');
                    $scope.bar.width('0');
                    $scope.files.html(xhr.responseText);
                }
            });
        };
        $scope.trustAsHtml = function (content) {
            return content;
            //return content != undefined ? content.replace(/通过/g, "通过<br/>").replace(/驳回/g, "驳回<br/>") : "";
        };
    });
    //    $("input").attr("disabled", "disabled");
    //    $("select").attr("disabled", "disabled");
</script>